import backgroud from "./backgrould";
import allVariableJs from "./allVariable";

cc.Class({
    extends: cc.Component,

    properties: {
        
        sprArray :{
            default:[],
            type:[cc.SpriteFrame],
        },
        spineBoom:cc.Node,
        starBoom:cc.Node,
       locationNum:cc.Integer,
       kindmouseNum:cc.Integer,
       giftLayout:cc.Node,
       mousebutton:cc.Button,
       backgroudJs:backgroud,
       audio: {
        default: null,
        type: cc.AudioClip
      },
       clickOneaudio: {
        default: null,
        type: cc.AudioClip
      },
      clickTwoaudio: {
        default: null,
        type: cc.AudioClip
      },
      clickThreeaudio: {
        default: null,
        type: cc.AudioClip
      },
      switchSound:{
        default: null,
        type: cc.AudioClip
      },

      appearSoundOne:{
        default: null,
        type: cc.AudioClip
      }
      ,
      appearSoundTwo:{
        default: null,
        type: cc.AudioClip
      },
      appearSoundThree:{
        default: null,
        type: cc.AudioClip
      },

      appearSwitchSound:{
        default: null,
        type: cc.AudioClip
      },
      hedgehogSound:{

        default: null,
        type: cc.AudioClip
      },

      boomMouseSound: {
        default: null,
        type: cc.AudioClip
      },

      iconIndex:cc.Integer,
      clickVoice:0,
      appearVoice:0

    },

    onLoad () {
          
        var spineBoomNode=cc.find("Canvas/backgroundtop/spineBoom")

        this.spineBoom=spineBoomNode

        this.starBoom=cc.find("Canvas/backgroundtop/spinnormal")


    },

    clickMouse:function(event){


        if(allVariableJs.SourceChange==true){
          
            cc.audioEngine.stop(this.current);

        }else{



        if(this.kindmouseNum==6){

            this.current = cc.audioEngine.play(this.hedgehogSound, false, 1);
            
        }else if(this.kindmouseNum==5){

            this.current = cc.audioEngine.play(this.boomMouseSound, false, 1);
        }
         else{

            switch(this.clickVoice){

                case 0:
                this.switchSound=this.clickOneaudio
                break;

                case 1:
                this.switchSound=this.clickTwoaudio
                break;

                case 2:
                this.switchSound=this.clickThreeaudio
                break;

                default:
                this.switchSound=this.clickThreeaudio
                break;
            }
        
            this.current = cc.audioEngine.play(this.switchSound, false, 1);

         }
           
        }
         var templocation=event.getLocation()

        this.backgroudJs.getComponent("backgrould").chuiziGetpointClick(templocation);

        if(this.kindmouseNum==9){

        }else{
            this.mousebutton.interactable=false
        }

            switch(this.kindmouseNum)
        {

        case 0:


        this.starAnimates()

        break;

        case 1:


        this.timeAnimates()

        break;

        case 2:


        this.chuiziAnimates()

        break;

        case 3:


        this.coinAnimates()

        break;

        case 4:


        this.waterAnimates()

        break;

        case 5:


        this.boomAnimates()



        break;

        case 6:

        this.hurtAnimates()

        break;

        case 7:

        this.lucencyMouse()

        break;


        case 8:

        this.waterMouse()

        break;


        case 9:

        this.ironMouse()

        break;

        default:
        this.otherMouse;

        break;

        }
   },

   otherMouse:function(){
    console.log("其他地鼠")
   },


   lucencyMouse:function(){

    console.log("透明地鼠")
    var hideAction = cc.hide();
    this.node.runAction(hideAction)
    this.starBoom.getComponent("starboom").init(this.locationNum)

    this.giftLayout.getComponent("giftlayout").init(this.locationNum,1)
    this.giftLayout.setContentSize(84,50)
    this.giftAddAnimates();
    var timeshowNode=cc.find("Canvas/topsprite/scoreShow")
    timeshowNode.getComponent("socreShow").addCoinStarNumber();

   },

   waterMouse:function(){

    console.log("水盆地鼠")

    var isEexitArray=allVariableJs.waterMouseNsArray.indexOf(this.node)

          if(isEexitArray>=0){
    
            allVariableJs.waterMouseNsArray.splice(isEexitArray,1)

            this.node.resumeAllActions()

            var hideAction = cc.hide();
            this.node.runAction(hideAction)

            this.starBoom.getComponent("starboom").init(this.locationNum)

          }else{

            console.log("水地鼠不在数组里面");

          }

   },

   ironMouse:function(){

    if(allVariableJs.isUseHammer){

        var hideAction = cc.hide();
        this.node.runAction(hideAction)
        this.mousebutton.interactable=false

        this.giftLayout.getComponent("giftlayout").init(this.locationNum,4)
        this.giftLayout.setContentSize(84,50)
        this.giftAddAnimates();
        var timeshowNode=cc.find("Canvas/topsprite/scoreShow")
        timeshowNode.getComponent("socreShow").addMoreCoinStarNumber();


    }else{
     
        this.iconIndex=this.iconIndex+1

        console.log("铁头地鼠",this.iconIndex)
        let that = this
           switch(this.iconIndex){
    
               case 1:
             
               cc.loader.loadRes("帽子地鼠1", cc.SpriteFrame, function (err, spriteFrame) {
                that.node.getComponent(cc.Sprite).spriteFrame = spriteFrame;
               });
    
               break;
    
               case 2:
          
               cc.loader.loadRes("帽子地鼠2", cc.SpriteFrame, function (err, spriteFrame) {
                 that.node.getComponent(cc.Sprite).spriteFrame = spriteFrame;
               });
               break;
    
               case 3:
         
               cc.loader.loadRes("帽子地鼠3", cc.SpriteFrame, function (err, spriteFrame) {
                 that.node.getComponent(cc.Sprite).spriteFrame = spriteFrame;
               });
               break;
    
               case 4:
    
               var hideAction = cc.hide();
               this.node.runAction(hideAction)
               this.starBoom.getComponent("starboom").init(this.locationNum)
               this.mousebutton.interactable=false

               this.giftLayout.getComponent("giftlayout").init(this.locationNum,4)
               this.giftLayout.setContentSize(84,50)
               this.giftAddAnimates();
               var timeshowNode=cc.find("Canvas/topsprite/scoreShow")
               timeshowNode.getComponent("socreShow").addMoreCoinStarNumber();
    
               break;
    
                default:
                break  ;
    
           }
    }
   },

//   // 1
    starAnimates:function(){
 
         var hideAction = cc.hide();
         this.node.runAction(hideAction)
         if(allVariableJs.isUseHammer){
            console.log("地鼠星星动画")
        }else{
            this.starBoom.getComponent("starboom").init(this.locationNum)    
        }    
         this.giftLayout.getComponent("giftlayout").init(this.locationNum,4)
         this.giftLayout.setContentSize(84,50)
         this.giftAddAnimates();
         var timeshowNode=cc.find("Canvas/topsprite/scoreShow")
         timeshowNode.getComponent("socreShow").addMoreCoinStarNumber();

    },


//   // 2
    timeAnimates:function(){

     
        var hideAction = cc.hide();
        this.node.runAction(hideAction)  
        if(allVariableJs.isUseHammer){
            console.log("地鼠时间动画")
        }else{
            this.starBoom.getComponent("starboom").init(this.locationNum)    
        } 
        this.giftLayout.getComponent("giftlayout").init(this.locationNum,6)
        this.giftLayout.setContentSize(119,51)
        this.giftAddAnimates();
        var timeshowNode=cc.find("Canvas/topsprite/timeshow")
        timeshowNode.getComponent("timeShow").addTimePropNumber();

    },



//   // 3
    chuiziAnimates:function(){
    
        var hideAction = cc.hide();
        this.node.runAction(hideAction)
        if(allVariableJs.isUseHammer){
            console.log("地鼠锤子动画")
        }else{
            this.starBoom.getComponent("starboom").init(this.locationNum)    
        } 
        this.giftLayout.getComponent("giftlayout").init(this.locationNum,2)
        this.giftLayout.setContentSize(85,55)
        this.giftAddAnimates();
        allVariableJs.chuiziCount=allVariableJs.chuiziCount+1;
        var chuizishowNode=cc.find("Canvas/chuiziBtn")
        chuizishowNode.getChildByName("hammerPropShow").getChildByName("hammerPropLabel").getComponent("NumberView").setText(allVariableJs.chuiziCount)
    },


   
//   // 4
    coinAnimates:function(){

        var hideAction = cc.hide();
        this.node.runAction(hideAction)
        if(allVariableJs.isUseHammer){
            console.log("金币动画")
        }else{
            this.starBoom.getComponent("starboom").init(this.locationNum)    
        } 
        this.giftLayout.getComponent("giftlayout").init(this.locationNum,0)
        this.giftLayout.setContentSize(83,49)
        this.giftAddAnimates();
        allVariableJs.wawaCoinAddNumber= allVariableJs.wawaCoinAddNumber+1
    
    },


//   // 5
    waterAnimates:function(){
    
        var hideAction = cc.hide();
        this.node.runAction(hideAction)
        if(allVariableJs.isUseHammer){
            console.log("正常地鼠")
        }else{
            this.starBoom.getComponent("starboom").init(this.locationNum)    
        } 

        this.giftLayout.getComponent("giftlayout").init(this.locationNum,1)
        this.giftLayout.setContentSize(84,50)
        this.giftAddAnimates();
        var timeshowNode=cc.find("Canvas/topsprite/scoreShow")
        timeshowNode.getComponent("socreShow").addCoinStarNumber();
 
  
    },


//   // 6
    boomAnimates:function(){
        
  
        var hideAction = cc.hide();
        this.node.runAction(hideAction)

        if(allVariableJs.isUseHammer){
            console.log("地鼠捧雷动画")
        }else{

         this.spineBoom.getComponent("boom").init(this.locationNum)
        }
        this.giftLayout.getComponent("giftlayout").init(this.locationNum,5)
        this.giftLayout.setContentSize(110,50)
        this.giftAddAnimates();
        var timeshowNode=cc.find("Canvas/topsprite/scoreShow")
        timeshowNode.getComponent("socreShow").minusStarNumber();

       var  miusstarNode=cc.find("Canvas/topsprite/boommius/miusstarNumber");

          miusstarNode.getComponent("NumberView").setLeftText(10,true)

          miusstarNode.active=true

          var changebig2 = cc.scaleTo(0.2,1.1);

          var changesmail2 = cc.scaleTo(0.1,1.0);

          var  delayAction=cc.delayTime(2);

          var finish = cc.callFunc(function(){
      
            miusstarNode.active=false    
            console.log("减分标志消失");
           

         }, this);
      
         var seq = cc.sequence(changebig2,changesmail2,delayAction,finish)

         miusstarNode.runAction(seq)

    },


//   // 7
    hurtAnimates:function(){

        console.log("地鼠刺猬动画")
        let that = this
        cc.loader.loadRes("刺猬地鼠2", cc.SpriteFrame, function (err, spriteFrame) {
            that.node.getComponent(cc.Sprite).spriteFrame = spriteFrame;
        });
        if(allVariableJs.isUseHammer){

            var hideAction = cc.hide();
            this.node.runAction(hideAction)

        }else{
            this.backgroudJs.getComponent("backgrould").showhurtAnimates();
        }
      
    },

    
    giftAddAnimates:function(){
        
    
        this.giftLayout.stopAllActions();//停止
        this.giftLayout.active=true
        var giftpoint=this.giftLayout.getPosition();
        var action = cc.moveTo(0.5, giftpoint.x,giftpoint.y+80);
   
        var finish = cc.callFunc(function(){

      
               this.giftLayout.active=false
            this.giftLayout.y=giftpoint.y
         
          }, this);

          var seq = cc.sequence(action,finish);
          this.giftLayout.runAction(seq);


    },

    onDestroy: function () {

        cc.audioEngine.stop(this.current);
  
    },

    init(type,locationMouse){


        if(allVariableJs.SourceChange==true){
          
            cc.audioEngine.stop(this.appearSound);

        }else{

            switch(this.appearVoice){

                case 0:
                this.appearSwitchSound=this.appearSoundOne
                break;

                case 1:
                this.appearSwitchSound=this.appearSoundTwo
                break;

                case 2:
                this.appearSwitchSound=this.appearSoundThree
                break;

                default:
                this.appearSwitchSound=this.appearSoundOne
                break;
            }
        
            this.appearSound = cc.audioEngine.play(this.appearSwitchSound, false, 1);
        }


        // console.log("地鼠种类",type)
    this.node.getComponent(cc.Sprite).spriteFrame=this.sprArray[type]
    
    this.node.active=true

    this.locationNum=locationMouse

    this.kindmouseNum=type

    this.mousebutton.interactable=true

}


});
